#include "Precomp.h"
#include "Logger.h"
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>

using namespace boost;
using namespace lambda;

Logger* Logger::instance=NULL;

Logger::Logger()
{
	assert(instance==NULL);
	instance=this;
}

Logger::~Logger()
{
}

void Logger::addTarget(std::wostream& target)
{
	targets.push_back(&target);
}

void Logger::log(const wchar_t* msg)
{
	for(std::list<std::wostream*>::iterator i=targets.begin();i!=targets.end();++i)
	{
		(**i)<<msg;
		(*i)->flush();
	}
}

void Logger::log(const char* msg)
{
	for(std::list<std::wostream*>::iterator i=targets.begin();i!=targets.end();++i)
	{
		(**i)<<msg;
		(*i)->flush();
	}
}

void Log(const wchar_t* msg,...)
{
	static wchar_t temp[1024];
    va_list vl;
    va_start(vl, msg);
    vswprintf( temp,1024,msg, vl);
    va_end(vl);
	Logger::instance->log(temp);
}

void Log(const char* msg,...)
{
	static char temp[1024];
    va_list vl;
    va_start(vl, msg);
    vsprintf( temp,msg, vl);
    va_end(vl);
	Logger::instance->log(temp);
}

void SquirrelLog(HSQUIRRELVM, const wchar_t* msg,...)
{
	static wchar_t temp[1024];
    va_list vl;
    va_start(vl, msg);
    vswprintf( temp,1024,msg, vl);
    va_end(vl);
	Logger::instance->log(temp);
}